# Maintainer: Mateusz Mikuła <mati865@gmail.com>

_realname=sqlcipher
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.6.1
pkgrel=1
pkgdesc="SQLite extension that provides transparent 256-bit AES encryption of database files (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.zetetic.net/sqlcipher/"
msys2_repository_url="https://github.com/sqlcipher/sqlcipher"
msys2_references=(
  "cpe: cpe:/a:zetetic:sqlcipher"
)
license=('spdx:BSD-3-Clause-Clear')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-readline")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-tcl")
source=("https://github.com/${_realname}/${_realname}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "02-fix-tcl-find.patch")
sha256sums=('d8f9afcbc2f4b55e316ca4ada4425daf3d0b4aab25f45e11a802ae422b9f53a3'
            'd30c43a28eaeedcafde98d0f9a76fd8d676ee77732c9dc38e028147faa5adca0')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/02-fix-tcl-find.patch

  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --enable-tempstore=yes \
    --disable-tcl \
    --enable-fts4 \
    --enable-fts5 \
    --enable-rtree \
    --enable-session \
    --disable-editline \
    --enable-readline \
    --with-readline-lib="-L${MINGW_PREFIX}/lib -lreadline" \
    --with-readline-inc="-I${MINGW_PREFIX}/include" \
    CFLAGS="$CFLAGS -DSQLITE_HAS_CODEC -DSQLITE_ENABLE_COLUMN_METADATA" \
    LDFLAGS="$LDFLAGS -lcrypto"

  make
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  make DESTDIR="${pkgdir}" install

  cd "${srcdir}"/${_realname}-${pkgver}
  install -Dm644 LICENSE.md "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
